package com.huilian.iotbox.admin.controller;

import com.huilian.iotbox.admin.service.MemberStoreBalanceService;
import com.huilian.iotbox.admin.service.UserService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.controller.BaseController;
import com.huilian.iotbox.data.po.MemberStoreBalance;
import com.huilian.iotbox.data.vo.UserInfo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author 谢洛涛
 * @date 2021/3/31 13:14
 */
@RestController
@RequestMapping("/api/memberStoreBalance")
public class MemberStoreBalanceController extends BaseController {
    @Resource
    private MemberStoreBalanceService memberStoreBalanceService;
    @Resource
    private UserService userService;
    @GetMapping("/consumeMember/{merchantStoreId}")
    public ServerResponse consumeMember(HttpServletRequest request, @PathVariable Integer merchantStoreId){
        MemberStoreBalance memberStoreBalance = new MemberStoreBalance();
        memberStoreBalance.setMerchantStoreId(merchantStoreId);
        UserInfo userInfo = userService.getLoginUserInfo(request);
        memberStoreBalance.setUserInfo(userInfo);
        return memberStoreBalanceService.consumeMember(memberStoreBalance);
    }
}
